import { _decorator, Component, Label, Node, Sprite, SpriteFrame } from 'cc';
import { BundleManager } from 'db://assets/Scripts/Framework/Managers/BundleManager';
import { MainUI } from '../MainUIs/MainUI';
import { GameDataManager } from '../GameDataManager';
const { ccclass, property } = _decorator;

@ccclass('ChestItemUI')
export class ChestItemUI extends Component {

    @property(Sprite)
    kuang: Sprite;

    @property(Sprite)
    item: Sprite;

    @property(Sprite)
    skin: Sprite;

    @property(Sprite)
    pieceSprite: Sprite;

    @property(Label)
    numLabel: Label;

    @property(Label)
    pieceLabel: Label;

    @property(Label)
    unlockLabel: Label;

    @property(Node)
    piece: Node;

    @property([SpriteFrame])
    kuangSfs: SpriteFrame[] = [];

    @property([SpriteFrame])
    itemSfs: SpriteFrame[] = [];

    start() {

    }

    update(deltaTime: number) {

    }

    Init(data: number[]) {
        this.kuang.spriteFrame = this.kuangSfs[data[0]];
        this.item.spriteFrame = this.itemSfs[data[0]];
        if (data.length == 1) {
            this.skin.spriteFrame = null;
            this.piece.active = false;
            this.unlockLabel.string = "";
        }
        else {
            let sf = MainUI.Instance.items.Adorn[data[1]][data[2]].spriteFrame;
            BundleManager.GetBundle("MainPack").load(sf, SpriteFrame, (err, data) => { this.skin.spriteFrame = data; });
            let data2 = GameDataManager.Instance.getArrayData<number[]>("AllSkin");
            if (data2[data[1]][data[2]] == 1) {
                this.piece.active = false;
                this.unlockLabel.string = "已解锁";
            }
            else {
                this.piece.active = true;
                data2 = GameDataManager.Instance.getArrayData<number[]>("SkinPieces");
                let num = data2[data[1]][data[2]];
                this.pieceLabel.string = `${num}/20`;
                if (num >= 20) this.unlockLabel.string = "可解锁";
                else this.unlockLabel.string = "";
            }
        }
        let str = "";
        switch (data[0]) {
            case 0:
                str = "50";
                break;
            case 1:
                str = "25";
                break;
            case 2:
                str = "1";
                break;
        }
        this.numLabel.string = str;
    }

}


